package org.vectrics.recruiter.web.user;

import java.util.*;

import org.apache.log4j.Category;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.user.Person;
import org.vectrics.user.PersonSearchCriteria;
import org.vectrics.common.util.PageList;
import org.vectrics.hibernate.ThreadProperties;


public class CandidatePageList extends PageList {
    private static Category log = Category.getInstance(CandidatePageList.class);

    
    protected Vector findKeys()
    {    
        HashSet roles = new HashSet();
        roles.add("recruit-candidate");
		PersonSearchCriteria criteria = CoreServiceLocator.createPersonSearchCriteria();

        Person authPerson = ThreadProperties.getPerson();
		Set domains = CoreServiceLocator.getPersonService()
			.findDomainsWithUserPrivilege(authPerson, Person.PRIVILEGE_PERSON_VIEW);
		criteria.setDomains(domains);
        
        criteria.setPrivileges(roles);
        Vector userIds = null;
        try {
        	userIds.addAll(CoreServiceLocator.getPersonService().findUserIds(criteria));
        }
        catch (Exception ex) {
        	log.error("Exception finding user ids", ex);
        }
        return(userIds);
    }

    protected Vector loadObjects(Vector userIds) {
        if (log.isDebugEnabled())
            log.debug("loadObjects() called.  Key count = " + userIds.size()); 
        Vector users = new Vector();
        users.addAll(CoreServiceLocator.getPersonService().loadUsers(userIds));
        return(users);
    }

        
}    

